package com.qk.service.impl;

import com.qk.mapper.BusinessMapper;
import com.qk.mapper.ClueMapper;
import com.qk.service.BusinessService;
import com.qk.service.ClueService;
import com.qk.service.ReportService;
import com.qk.vo.OverviewVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
   private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public OverviewVo getOverview() {
        //设置redis
        Object value = redisTemplate.opsForValue().get("overViewVoKey");
        if (value != null) {
            return (OverviewVo) value;
        }
        OverviewVo overClueviewVo =  clueMapper.selectClueOverview();
        OverviewVo overBusinessviewVo =  businessMapper.selectBusinessOverview();
        BeanUtils.copyProperties(overClueviewVo,overBusinessviewVo,"businessTotal","businessWaitAllot","businessWaitFollow","businessFollowing","businessFalse","businessConvertCustomer");
        redisTemplate.opsForValue().set("overViewVoKey",overBusinessviewVo,1, TimeUnit.MINUTES);
        return overBusinessviewVo;
    }
}
